<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/1
 * Time: 16:04
 */
namespace application\test;
class user{
    private $userArr = null;
    private $passArr = null;
//    private $idCount = 0;
    private $idCount;
    protected $level = 0;
    protected $life = 500;



    public function __construct()
    {
        echo "Class begin.<br>";
    }

    /**
     * @param $userId 用户名
     * @param $password 密码
     */
    public function register($userId,$password){
        echo "你需要注册一个账户<br>";
        $this->idCount = date("YmdHis").rand(100000,999999);

//        $this->userArr[] = [$this->idCount =>$userId];
        $this->userArr[$this->idCount] = $userId;
        $this->passArr[$this->idCount] = $password;
        echo "创建成功,您的密钥为 ".$this->idCount." 请妥善保管<br>";
        $this->idCount++;
    }

    /**
     * @param $userId 用户名
     * @param $password 密码
     * @param $key 密钥
     */
    public function login($userId,$password,$key){
        echo "正在验证数据<br>";
//        print_r($this->userArr);
//        print_r("|".$this->userArr[0]."|");
        if($this->userArr[$key] == $userId && $this->passArr[$key] == $password){
            echo "登录成功<br>";
        }
    }

    /**
     * @param $password 密码
     * @param $newPass 新密码
     * @param $key id 密钥
     */
    public function exchangeKeyword($password,$newPass,$key){
        if($this->userArr[$key] == $password){
            $this->passArr[$key] = $newPass;
        }

    }

    /**
     * 我累了
     */
    public function updateYourself(){
        echo "调用update";
    }

    public function __destruct()
    {
        echo "<br>Class end.<br>";
    }
}